﻿#ifndef _FILE_MANAGER_H_SET_
#define  _FILE_MANAGER_H_SET_

#include "file_manager.h"

#include <vector>

using namespace std;

class CFile_manager_arr
{
public:
	CFile_manager_arr();
	~CFile_manager_arr();

	int Init(int chNum);
	int GetRecorInfo();
	
	int InitSorageDir(char * storageName,RECORD_DIR_INFO_S recDir);

	int AddFileManager(char * storageName,RECORD_DIR_INFO_S recDir);

	void RemoveFileManager(char * storageName);

	int Reset();
	int Close();

	int GetCycleIndex(uint32_t channel,string & filename,uint16_t & diskIndex, uint32_t & indexNo,uint32_t & fileLen,time_t recTm);
	//回收空间
	int CycleRecord();

	//开始录像
	int RecordStart(REC_FILE_INFO & recInfo);

	//停止录像
	int RecordEnd(REC_FILE_INFO & recInfo);

	int LockFile(REC_FILE_INFO & recInfo);

	int UnlockFile(REC_FILE_INFO & recInfo);

	int RegisterRecWriter(int diskIdx,int ch, CRecWriteBase * pRec);

	int DestroyRecWriter(int diskIdx,int ch);

	//获取下一个文件
	int GetNextRecIndex(uint32_t channel,uint16_t & diskIndex ,string & fileName, uint32_t & fileIndex, uint32_t & fileSize,time_t recTm,int recType);

	int SearchRecord(uint64_t tm_start,int64_t tm_end, int recType,vector<uint8_t>& vecCH,uint32_t maxNum,MAP_CH_FILE_T& mapPerChFile,bool bForward);

	CFile_manager* GetDiskFileManager(int diskNo);
	void SetRecordSize(uint32_t fileSize);
	
	void SetSwitchFileParm(int switchMode, int parm);

	int GetFilePath(char * fileName, FILE_INFO & fInfo);

	uint32_t GetCurDiskNO()
	{
		return m_curDiskNo;
	}
	uint32_t GetNextRecordSN();
	void GetMaxTime(time_t &maxTm);

	int GetLeafRecNum();
	int GetLeafFileNum();
	int GetDiskNum();
	uint32_t GetFreeSpaceMB();
	int GetDataPercent();

	int ScanDevice();
	char * GetDiskName(int diskIndex);
	int GetNextPic(string & picFile,time_t curTm, int channel);

#ifdef _SIMULATE_RECORD_
	void SetStoragePath(char * path)
	{
		m_vec_file_man[0]->SetStoragePath(path);
	}
#endif
	void SetNorSpace(uint32_t space);
	void SetNorSpace(uint32_t space,char * dev);
protected:
	vector<CFile_manager *>  m_vec_file_man;
	uint32_t m_curDiskNo;
	CCross_Lock		 m_lock;
	uint32_t m_chNum;
};

extern CFile_manager_arr          g_pFileMangerArr;
#define LITTLE_SIZE_MB  16
#endif
